<template>
  <div id="dict_manage" class="container">
    <div class="content">
      <!-- <div class="title">数据字典管理</div> -->
      <div class="panel">
        <div class="condition">
          <div class="row_one">
            <el-input
              style="width: 3.5rem;"
              placeholder="搜索 数据字典名称、类型"
              suffix-icon="el-icon-search"
              v-model="tabledisplayObj.generalTerm"
              @input="searchSysdict()"
              clearable
              class="input_search"
            ></el-input>

            <div class="right_btn" @click="openAdd">新&nbsp&nbsp增</div>
          </div>
        </div>
        <div>
          <table class="table" cellspacing="0">
            <thead class="thead">
              <tr>
                <td style="width: 4rem;">类型</td>
                <td style="width: 3rem;">名称</td>
                <td style="width: 3rem;">值</td>
                <td style="width: 3rem;">键</td>
                <td style="width: 2rem;">排序号</td>
                <td style="width: 3rem;">版本号</td>
                <td style="width: 4rem;">操作</td>
              </tr>
            </thead>
            <tbody class="tbody">
              <tr v-for="item,index in sysdictList">
                <td>{{item.remark}}</td>
                <td>{{item.name}}</td>
                <td>{{item.dicValue}}</td>
                <td>{{item.dicKey}}</td>
                <td>{{item.orderBy}}</td>
                <td>{{item.version}}</td>
                <td>
                  <span class="operate_btn" @click="handleEdit(index,item)">编辑</span>
                  &nbsp;
                  <span
                    class="operate_btn"
                    @click="handleDelete(index,item)"
                  >删除</span>
                  &nbsp;
                  <span
                    class="operate_btn"
                    @click="handleAdd(index,item)"
                  >扩展</span>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <el-pagination
          class="page"
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="tabledisplayObj.currPage"
          @size-change="pageSizeChange"
          @current-change="tabledisplayChangePage"
          :total="tabledisplayObj.total"
        ></el-pagination>
      </div>
    </div>
    <createDict ref="createDict" @callback="closeAdd"></createDict>
    <dictUpdate ref="dictUpdate" @callback="closeAdd"></dictUpdate>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions } from "vuex"; //先要引入
import createDict from "./common/createDict";
import dictUpdate from "./common/dictUpdate";
let vm;
let user;
export default {
  data() {
    return {
      tabledisplayObj: {
        currPage: 1,
        pageSize: 10,
        total: 0,
        generalTerm: ""
      },
      sysdictList: []
    };
  },
  components: {
    createDict,
    dictUpdate
  },
  methods: {
    /**
     * 初始化数据
     */
    initData() {
      this.getData(vm.tabledisplayObj);
    },
    /**
     * 抽取出来获取课程类别列表
     */
    getData(paras) {
      api.sysdictList(paras).then(function(data) {
        if (data.resultCode == 2000) {
          vm.sysdictList = data.list;
          vm.tabledisplayObj.total = data.totalCount;
        } else {
          vm.$message.error(data.message);
        }
      });
    },
    openAdd() {
      vm.$refs.createDict.init({});
    },
    closeAdd(data) {
      console.log(data);
      this.initData();
    },
    pageSizeChange: function(val) {
      //页条数发生改变
      vm.tabledisplayObj.pageSize = val;
      this.getData(vm.tabledisplayObj);
    },
    /**表格显示形式翻页 */
    tabledisplayChangePage(val) {
      console.log(val);
      vm.tabledisplayObj.currPage = val;
      this.getData(vm.tabledisplayObj);
    },
    /**
     * 点击编辑
     */
    handleEdit(index, row) {
      console.log(index, row);
      vm.$refs.dictUpdate.init(tool.clone(row));
    },
    /**
     * 扩展
     */
    handleAdd(index,row){
      vm.$refs.createDict.init(tool.clone(row));
    },
    /**
     * 点击删除
     */
    handleDelete(index, row) {
      this.$confirm("此操作将删除该数据字典, 是否继续?", "温馨提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          let paras = {
            id: row.id
          };
          api.sysdictDelete(paras).then(function(data) {
            if (data.resultCode == 2000) {
              vm.$message({
                message: "删除成功",
                type: "success"
              });
              vm.initData();
            } else {
              vm.$message.error(data.message);
            }
          });
        })
        .catch(() => {});
    },
    /**
     * 搜索
     */
    searchSysdict() {
      vm.tabledisplayObj.currPage = 1;
      vm.initData();
    }
  },
  mounted() {
    vm = this;
    user = tool.getItem(lsKey.user, true); //得到当前用户信息
    this.initData();
  },
  computed: {}
};
</script>

<style lang="scss">
#dict_manage {
  .el-input__inner {
    border-radius: 0.08rem;
    font-size: 0.16rem;
    color: #666666;
    height: 0.36rem;
    line-height: 0.36rem;
  }
  .el-input__icon {
    line-height: 0.36rem;
  }

  .input_search {
    .el-input__inner {
      background-color: rgb(247, 248, 250);
    }
  }
}
</style>
<style scoped src="@/style/module/table.css"></style>
<style scoped src="@/style/clue_manage/clue_manage.css"></style>
<style scoped>
.right_btn {
  background-image: url(../../assets/img/clue_manage/add_white.png);
  width: 1.54rem;
}
</style>